package com.csgc.camera.widget.mask

import android.content.Context
import android.graphics.Color
import android.util.TypedValue
import android.view.LayoutInflater
import android.view.View
import android.widget.TextView

import com.csgc.camera.constants.MaskConfig
import com.csgc.camera.storage.MaskPreference
import com.cysd.spsyxj.R


class MaskCanYin:MaskBase {


    private var cleanContent:TextView?=null
    private var cleanPerson:TextView?=null
    private var cleanArea:TextView?=null

    private var liuYangRen:TextView?=null

    constructor(context: Context?, id:Int) : super(context,null){
        if(id == 0){
            remarkNeedTitle = false
            LayoutInflater.from(context).inflate(R.layout.item_mask_can_yin_1, this, true)
        }else if(id == 1){
            LayoutInflater.from(context).inflate(R.layout.item_mask_can_yin_2, this, true)
        }else if(id == 2){
            remarkNeedTitle = false
            LayoutInflater.from(context).inflate(R.layout.item_mask_can_yin_3, this, true)
        }else if(id == 3){
            remarkNeedTitle = false
            LayoutInflater.from(context).inflate(R.layout.item_mask_can_yin_4, this, true)
        }

        dateStyle = "yyyy-MM-dd EEEE"
        if(MaskConfig.maskDateStyle.isNotEmpty()){
            dateStyle = MaskConfig.maskDateStyle
        }
        initView()

    }

    private fun initView(){
        date = findViewById(R.id.tv_can_yin_date)
        location = findViewById(R.id.tv_can_yin_location)
        customMaskContainer = findViewById(R.id.layout_custom_mask_container)
        remark = findViewById(R.id.tv_can_yin_remark)
        remarkLayout = findViewById(R.id.layout_can_yin_remark)

        cleanContent = findViewById(R.id.tv_can_yin_clean_content)
        cleanPerson = findViewById(R.id.tv_can_yin_clean_person)
        cleanArea = findViewById(R.id.tv_can_yin_clean_area)

        liuYangRen = findViewById(R.id.tv_can_yin_liu_yang)

        location?.text = MaskConfig.maskLocation

        changeDateTime()
        MaskConfig.customMaskInfo.forEach {
            val text = TextView(context)
            text.setTextColor(Color.WHITE)
            text.setTextSize(TypedValue.COMPLEX_UNIT_SP,12f)
            text.text = "${it.title}:${it.content}"
            text.visibility = if (it.isOpen) View.VISIBLE else View.GONE

            customMaskContainer?.addView(text)
        }

        val maskType = MaskPreference.instance.getMaskType()
        MaskConfig.maskMap[maskType]?.forEach {
            if(it.title == "清洁内容"){
                cleanContent?.text = it.content
            }else if(it.title == "负责任人"){
                cleanPerson?.text = it.content
            }else if(it.title == "清洁区域"){
                cleanArea?.text = it.content
            }else if(it.title == "留样人"){
                liuYangRen?.text = it.content
            }
        }


    }

    override fun updateItemContent(title: String, content: String) {
        super.updateItemContent(title, content)
        if(title == "清洁内容"){
            cleanContent?.text = content
        }else if(title == "负责任人"){
            cleanPerson?.text = content
        }else if(title == "清洁区域"){
            cleanArea?.text = content
        }else if(title == "留样人"){
            liuYangRen?.text = content
        }
    }
}